package org.springblade.modules.admin.controller.feishu;

import lombok.AllArgsConstructor;
import org.springblade.common.enums.FeiShuDocumentEnum;
import org.springblade.core.tool.api.R;
import org.springblade.modules.admin.dto.UserSignDetailDTO;
import org.springblade.modules.admin.entity.MaintainPlanContent;
import org.springblade.modules.admin.entity.UserSignDetail;
import org.springblade.modules.admin.service.feishu.IFeiShuDocumentService;
import org.springblade.modules.admin.service.feishu.ILarkMaintenanceService;
import org.springblade.modules.admin.service.feishu.ILarkSyncService;
import org.springblade.modules.admin.task.feishu.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.web.bind.annotation.*;

/**
 * @author: Sharry
 * @createTime: 2024-05-15 19:06
 * @version: Version-1.0
 */
@RestController
@AllArgsConstructor
@RequestMapping("/admin/lark/galaxy")
public class LarkGalaxyController {

	private final LarkElevatorMaintenanceRiskDataJob larkElevatorMaintenanceRiskDataJob;

	private final LarkElevatorDailyAttendanceJob larkElevatorDailyAttendanceJob;

	private final LarkElevatorScoreJob larkElevatorScoreJob;

	private final ILarkMaintenanceService maintenanceService;

	private final LarkMaintainElevatorContractJob larkMaintainElevatorContractJob;

	private final LarkContractContinueJob larkContractContinueJob;

	private final ILarkSyncService larkSyncService;

	private final LarkRescueAndFaultIndexJob larkRescueAndFaultIndexJob;

	/**
	 * 电梯合规数据表副本
	 * @return R 成功返回true
	 */
	@GetMapping("/test/elevator/maintenance/risk/data")
	public R<Boolean> getElevatorMaintenanceRiskDataTest() {
		this.executeElevatorMaintenanceRiskDataJobTest();
		return R.data(true);
	}

	/**
	 * 电梯合规数据表副本，异步执行
	 */
	public void executeElevatorMaintenanceRiskDataJobTest() {
		larkElevatorMaintenanceRiskDataJob.galaxyElevatorMaintenanceRiskDataCopyAsync();
	}

	/**
	 * 电梯合规数据表
	 * @return R ，异步执行
	 */
	@GetMapping("/elevator/maintenance/risk/data")
	public R<Boolean> getElevatorMaintenanceRiskData() {
		this.executeElevatorMaintenanceRiskDataJob();
		return R.data(true);
	}

	/**
	 * 电梯合规数据表,异步执行
	 */
	public void executeElevatorMaintenanceRiskDataJob() {
		larkElevatorMaintenanceRiskDataJob.galaxyElevatorMaintenanceRiskDataAsync();
	}


	/**
	 * 逾期风险数据表副本
	 * @return R，异步执行
	 */
	@GetMapping("/test/elevator/maintenance/overdue")
	public R<Boolean> getElevatorMaintenanceOverdueTest() {
		larkSyncService.overdueTaskTest();
		return R.data(true);
	}

	/**
	 * 逾期风险数据表
	 * @return R 成功返回true
	 */
	@GetMapping("/elevator/maintenance/overdue")
	public R<Boolean> getElevatorMaintenanceOverdue() {
		larkSyncService.overdueTask();
		return R.data(true);
	}

	/**
	 * 每日考勤数据表副本
	 */
	@GetMapping("/test/elevator/daily/attendance")
	public void elevatorDailyAttendanceTest() {
		larkElevatorDailyAttendanceJob.galaxyElevatorDailyAttendanceJobCopy();
	}

	/**
	 * 每日考勤数据表
	 */
	@GetMapping("/elevator/daily/attendance")
	public void elevatorDailyAttendance() {
		larkElevatorDailyAttendanceJob.galaxyElevatorDailyAttendanceJob();
	}

	@PostMapping("/elevator/daily/attendance/person")
	public void elevatorDailyAttendancePerson(@RequestBody UserSignDetailDTO userSignDetailDTO) {
		String activeProfile = System.getProperty("spring.profiles.active");
		if ("prod".equals(activeProfile)) {
			larkElevatorDailyAttendanceJob.galaxyElevatorDailyAttendancePerson(userSignDetailDTO);
		} else {
			larkElevatorDailyAttendanceJob.galaxyElevatorDailyAttendancePersonCopy(userSignDetailDTO);
		}
	}

	@PostMapping("/elevator/repair/plan")
	public void getElevatorRepairPlan(@RequestBody MaintainPlanContent maintainPlanContent) {
		Long planId = maintainPlanContent.getId();
		String activeProfile = System.getProperty("spring.profiles.active");
		if ("prod".equals(activeProfile)) {
			maintenanceService.sendRepairLarkMessage(planId);
		} else {
			maintenanceService.sendRepairLarkMessageCopy(planId);
		}
	}

	@GetMapping("elevator/repair/plan/flush")
	public void flushElevatorRepairPlan() {
		String activeProfile = System.getProperty("spring.profiles.active");
		if ("prod".equals(activeProfile)) {
			maintenanceService.flushRepairLarkFlush();
		} else {
			maintenanceService.flushRepairLarkFlushCopy();
		}
	}

	/**
	 * 正式表格手动执行接口：评分补偿
	 */
	@GetMapping("/update/maintain/repair/score/byHand")
	public String updateMaintainCustomerByHand() {
		larkElevatorScoreJob.sendPlanScoreLarkMessageTempFull();
		return "success";
	}

	/**
	 * 每日考勤统计接口
	 */
	@GetMapping("/elevator/daily/attendance/statistics/copy")
	public void elevatorDailyAttendanceStatisticsCopy() {
		larkElevatorDailyAttendanceJob.galaxyElevatorDailyAttendanceStaticCopyJob();
	}

	/**
	 * 每日考勤统计接口
	 */
	@GetMapping("/elevator/daily/attendance/statistics")
	public void elevatorDailyAttendanceStatistics() {
		larkElevatorDailyAttendanceJob.galaxyElevatorDailyAttendanceStaticJob();
	}


	@GetMapping("/test/elevator/daily/attendance/compensate")
	public void elevatorDailyAttendanceCompensateCopy() {
		larkElevatorDailyAttendanceJob.galaxyElevatorDailyAttendanceCompensateJobCopy();
	}

	@GetMapping("/elevator/daily/attendance/compensate")
	public void elevatorDailyAttendanceCompensate() {
		larkElevatorDailyAttendanceJob.galaxyElevatorDailyAttendanceCompensateJob();
	}

	/**
	 * 每日考勤统计接口补偿
	 */
	@GetMapping("/test/elevator/daily/attendance/statistics/compensate")
	public void elevatorDailyAttendanceStatisticsCompensateCopy() {
		larkElevatorDailyAttendanceJob.galaxyElevatorDailyAttendanceStaticCompensateJobCopy();
	}

	/**
	 * 每日考勤统计接口补偿
	 */
	@GetMapping("/elevator/daily/attendance/statistics/compensate")
	public void elevatorDailyAttendanceStatisticsCompensate() {
		larkElevatorDailyAttendanceJob.galaxyElevatorDailyAttendanceStaticCompensateJob();
	}

	/**
	 * 宇航的已排期电梯合同表格
	 */
	@GetMapping("/elevator/maintenance/schedule/contract")
	public void elevatorMaintenanceScheduleCopy() {
		larkMaintainElevatorContractJob.galaxyScheduledMaintainElevatorContractJob();
	}

	/**
	 * 宇航的合同续签表格
	 */
	@GetMapping("contract/continue")
	public void contractContinue() {
		larkContractContinueJob.galaxyLarkContractContinueJob();
	}


	/**
	 * 天雄的救援故障仪表盘救援工单明细
	 */
	@GetMapping("/rescue/plan/detail")
	public void larkGalaxyRescuePlanDetail(){
		larkRescueAndFaultIndexJob.galaxyRescuePlanDetailJob();
	}

	/**
	 * 天雄的救援故障仪表盘救援按月健康指标
	 */
	@GetMapping("/rescue/monthly/health/index")
	public void larkGalaxyRescueMonthlyHealthIndex(){
		larkRescueAndFaultIndexJob.galaxyMonthlyRescueHealthIndexJob();
	}

	/**
	 * 天雄的救援故障仪表盘救援按周健康指标
	 */
	@GetMapping("/rescue/weekly/health/index")
	public void larkGalaxyRescueWeeklyHealthIndex(){
		larkRescueAndFaultIndexJob.galaxyWeeklyRescueHealthIndexJob();
	}

	/**
	 * 天雄的救援故障仪表盘维修计划明细
	 */
	@GetMapping("/repair/plan/detail")
	public void larkGalaxyRepairPlanDetail(){
		larkRescueAndFaultIndexJob.galaxyRepairPlanDetailJob();
	}

	/**
	 * 天雄的救援故障仪表盘维修按月健康指标
	 */
	@GetMapping("/repair/monthly/health/index")
	public void larkGalaxyRepairMonthlyHealthIndex(){
		larkRescueAndFaultIndexJob.galaxyMonthlyRepairHealthIndexJob();
	}

	/**
	 * 天雄的救援故障仪表盘维修按周健康指标
	 */
	@GetMapping("/repair/weekly/health/index")
	public void larkGalaxyRepairWeeklyHealthIndex(){
		larkRescueAndFaultIndexJob.galaxyWeeklyRepairHealthIndexJob();
	}

	/**
	 * 天雄的救援故障仪表盘风险事件明细
	 */
	@GetMapping("/risk/event/detail")
	public void larkGalaxyRiskEventDetailJob(){
		larkRescueAndFaultIndexJob.galaxyRiskEventDetailJob();
	}

	/**
	 * 天雄的救援故障仪表盘风险事件按日指标
	 */
	@GetMapping("/daily/risk/event/index")
	public void larkGalaxyDailyRiskEventIndexJob(){
		larkRescueAndFaultIndexJob.galaxyDailyRiskEventIndexJob();
	}

	/**
	 * 宇航的合同丢保率+日周月趋势表
	 */
	@GetMapping("/contract/lost/rate/trend")
	public void larkGalaxyContractLostRateTrend(){
		larkContractContinueJob.galaxyLarkContractLoseRateJob();
	}

	/**
	 * 宇航的及时续约率日周月详细趋势表
	 */
	@GetMapping("/contract/continue/rate/trend")
	public void larkGalaxyContractContinueTimelinessRateTrend(){
		larkContractContinueJob.galaxyLarkContractContinueTimelinessJob();
	}

	@GetMapping("/contract/continue/timeliness")
	public void larkGalaxyContractContinueTimeliness(){
		larkContractContinueJob.galaxyLarkContractContinueTimelinessJob();
	}




}
